//https://www.bilibili.com/video/BV1d54y1f7B3/?spm_id_from=333.337.search-card.all.click&vd_source=d6fe65f095f01f05591e89d810720ccc
// 2024-10-18


public class P006_x的平方根_牛顿迭代 {

    public static void main(String[] args) {
        System.out.println(my_sqrt(98));
    }

    // 求x的平方根的整数部分，x/n = n , (x/n+n)/2=? 不断迭代(牛顿迭代公式，逼近思想)
    private static int my_sqrt(int x) {
        if (x == 0) return 0;
        return (int)fun(x,x);
    }

    private static double fun(double i,int x) {
        double res = (x/i + i) / 2;
        if (res == i) return i;
        else return fun(res,x);
    }


}
